package com.pearadmin.pro.modules.courseManagement.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pearadmin.pro.common.context.UserContext;
import com.pearadmin.pro.modules.courseManagement.domin.ClassSchedule;
import com.pearadmin.pro.modules.courseManagement.repository.ClassScheduleRepository;
import com.pearadmin.pro.modules.courseManagement.service.ClassScheduleService;
import com.pearadmin.pro.modules.sys.domain.SysConfig;
import com.pearadmin.pro.modules.sys.repository.SysConfigRepository;
import com.pearadmin.pro.modules.sys.service.SysConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ClassScheduleServiceImpl extends ServiceImpl<ClassScheduleRepository, ClassSchedule> implements ClassScheduleService {

    @Resource
    private ClassScheduleRepository classScheduleRepository;

    @Resource
    private UserContext userContext;

    @Override
    public List<ClassSchedule> getOneList(String userId) {
        List<ClassSchedule> oneList = classScheduleRepository.getOneList(userId);
        if(oneList.size()== 0){
            for (int i = 1; i <=10 ; i++) {
                int front = 7;
                int queen = 8;
                if(i>=5 && i<9){
                    front+=2;
                    queen+=2;
                }else if(i>=9){
                    front+=3;
                    queen+=3;
                }
                ClassSchedule classSchedule = new ClassSchedule();
                classSchedule.setSort(i);
                classSchedule.setUserid(userId);
                classSchedule.setSchooltime((front+i+":00")+"-"+(queen+i+":00"));

                classScheduleRepository.insert(classSchedule);
            }
            oneList = classScheduleRepository.getOneList(userId);
        }
        return oneList;
    }
}
